package jsyf.oa.dao.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import jsyf.oa.entity.system.MilkEntity;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;

/**
 * Created by Administrator on 2018/11/8 0008.
 */
@Repository
public class MilkDao extends BaseDao {

    public MilkDao() {
        super.iBaseEntity = new MilkEntity();
    }

    public List<MilkEntity> getEntityListByCondition(String condition, Object[] params) {
        List<JSONObject> jsonList = getJSONListByCondition(condition, params);
        List<MilkEntity> entityList = new ArrayList<>();
        for (int i = 0; i < jsonList.size(); i++) {
            MilkEntity entity = (MilkEntity) convertJson2Entity(jsonList.get(i));
            entityList.add(entity);
        }
        return entityList;
    }
    public IBaseEntity getIBaseEntityByInformation(String information) {
        List<IBaseEntity> entityList = this.getIBaseEntityByCondition(" AND INFORMATION = ?", new Object[]{information});
        if (entityList != null && entityList.size() > 0) {
            return entityList.get(0);
        } else {
            return null;
        }
    }
    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, MilkEntity.class);
    }

    public JSONObject isWxId(String wxId) {
        String sql = "select count(1) as count,INFORMATION as information,BUY_FLAG as buyFlag from t_sys_milk WHERE WX_ID = ? ";
        return super.queryForJsonObject(sql.toString(),new Object[]{wxId});
    }

}

